﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace HAL9006.Terminal
{
    public class ThemeCommand : ITerminalCommand
    {
        public string Execute(params string[] parameters)
        {
            string script = string.Empty;

            string theme = parameters.FirstOrDefault();
            if (!string.IsNullOrWhiteSpace(theme))
            {
                script = string.Format(@"
                            var themeFullPath = $('#theme').attr('href');
                            var objRegExp = /(\w+)-(\w+).(\w+)/;
                            themeFullPath= themeFullPath.replace(objRegExp, '$1-{0}.$3');    
                            $.get(themeFullPath, function(){{
                                $('#theme').attr('href', themeFullPath);
                            }}).error(function() {{ console.log('wrong theme'); }})
                            ", theme);
            }
            return script;
        }
    }
}
